from toee import *
from utilities import *
import _include
from co8Util.TimedEvent import *


def san_dialog( attachee, triggerer ):
	if (attachee.leader_get() != OBJ_HANDLE_NULL):
		triggerer.begin_dialog( attachee, 120 )
	else:
		triggerer.begin_dialog( attachee, 1 )
	return SKIP_DEFAULT

def san_dying( attachee, triggerer ):
	game.global_flags[150] = 1
	if (attachee.leader_get() != OBJ_HANDLE_NULL):
		game.global_vars[29] = game.global_vars[29] + 1
	return RUN_DEFAULT

def san_first_heartbeat( attachee, triggerer ):
	itemF = attachee.item_find(2201)
	if (itemF != OBJ_HANDLE_NULL):
		itemF.item_flag_set(OIF_NO_TRANSFER)
	return RUN_DEFAULT

def san_resurrect( attachee, triggerer ):
	game.global_flags[150] = 0
	return RUN_DEFAULT

def san_join( attachee, triggerer ):
	itemD = attachee.item_find(2201)
	if (itemD != OBJ_HANDLE_NULL):
		itemD.item_flag_set(OIF_NO_TRANSFER)
	return RUN_DEFAULT

def san_new_map( attachee, triggerer ):
	if ((attachee.map == 5062) or (attachee.map == 5138) or (attachee.map == 5112) or (attachee.map == 5001)):
		leader = attachee.leader_get()
		if (leader != OBJ_HANDLE_NULL):
			leader.begin_dialog( attachee, 130 )
	return RUN_DEFAULT

def run_off( attachee, triggerer ):
	game.global_flags[151] = 1
	attachee.runoff(attachee.location-3)
	return RUN_DEFAULT

def check_follower_thrommel_comments( attachee, triggerer ):
	npc = find_npc_near( attachee, 8014)
	if (npc != OBJ_HANDLE_NULL):
		triggerer.begin_dialog( npc, 490 )
	else:
		npc = find_npc_near( attachee, 8000)
		if (npc != OBJ_HANDLE_NULL):
			triggerer.begin_dialog( npc, 550 )
		else:
			triggerer.begin_dialog( attachee, 10 )
	return RUN_DEFAULT

def schedule_reward( attachee, triggerer ):
	game.global_flags[152] = 1
	attachee.object_flag_set(OF_OFF)
	timedEventAdd(give_reward, (), 336)
	return RUN_DEFAULT

def give_reward():
	game.encounter_queue.append(3001)
	return RUN_DEFAULT

def san_spell_cast( attachee, triggerer, spell ):
	if ( spell.spell == spell_dispel_magic ):
		triggerer.begin_dialog( attachee, 1 )
	return RUN_DEFAULT

def san_true_seeing( attachee, triggerer ):
	if (attachee.can_see(triggerer)):
		triggerer.begin_dialog( attachee, 1 )
	return RUN_DEFAULT

def equip_transfer( attachee, triggerer ):
	itemA = attachee.item_find(3014)
	if (itemA != OBJ_HANDLE_NULL):
		itemA.item_flag_unset(OIF_NO_TRANSFER)
		attachee.item_transfer_to(triggerer,3014)
	return RUN_DEFAULT

def equip_transfer2( attachee, triggerer ):
	if anyone( game.leader.group_list(), "has_item", 2201):
		party_transfer_to( attachee, 2201 )
	return RUN_DEFAULT
